//
//  SettingViewController.m
//  MoneyBook
//
//  Created by Justin Kim on 11. 6. 27..
//  Copyright 2011 Daum. All rights reserved.
//

#import "SettingViewController.h"

//static NSString *kCellIdentifier = @"MyIdentifier";

@implementation SettingViewController
@synthesize dataSourceArray = _dataSourceArray;
/////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.dataSourceArray = [NSArray arrayWithObjects:
                                [NSArray arrayWithObjects:
                                     @"About MoneyBook",
                                     nil],
                                [NSArray arrayWithObjects:
                                    @"분류 관리",
                                    @"거래처 관리",
                                    @"현금 관리",
                                    @"은행 관리",
                                    @"카드 관리",
                                    @"태그 관리",                                
                                    nil],
                                [NSArray arrayWithObjects:
                                    @"암호 설정",
                                    @"데이터 백업",
                                    nil],
                                nil];    
        NSLog(@"init %d, %d, %d, %d", 
              [_dataSourceArray count]
              , [_dataSourceArray objectAtIndex:0]
              , [_dataSourceArray objectAtIndex:1]
              , [_dataSourceArray objectAtIndex:2]);
    }   
    return self;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc{
    [_dataSourceArray release];
    [super dealloc];
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle
/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewDidLoad{
    [super viewDidLoad];
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewDidUnload{
    self.dataSourceArray = nil;
    [super viewDidUnload];
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
	[super shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    return YES;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    
}
- (void)navigation:(UIViewController*)viewController{
}
#pragma mark -
#pragma mark UITableViewDelegate
/////////////////////////////////////////////////////////////////////////////////////////////////
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UIViewController* viewController;
    if(indexPath.section==0){
        if(indexPath.row==0){
            viewController = [[[AboutViewController alloc] initWithNibName:@"AboutView" bundle:nil] autorelease];
        }
    }else if(indexPath.section==1){
        if(indexPath.row==0){
            viewController = [[[ItemGroupSettingViewController alloc] initWithNibName:@"ItemGroupSetting" bundle:nil] autorelease];
        }else if(indexPath.row==1){
            viewController = [[[ShopSettingViewController alloc] initWithNibName:@"ShopSettingView" bundle:nil] autorelease];
        }else if(indexPath.row==2){
            viewController = [[[CashSettingViewController alloc] initWithNibName:@"CashSettingView" bundle:nil] autorelease];
        }else if(indexPath.row==3){
            viewController = [[[BankSettingViewController alloc] initWithNibName:@"BankSettingView" bundle:nil] autorelease];
        }else if(indexPath.row==4){
            viewController = [[[CardSettingViewController alloc] initWithNibName:@"CardSettingView" bundle:nil] autorelease];
        }else if(indexPath.row==5){
            viewController = [[[TagSettingViewController alloc] initWithNibName:@"TagSettingView" bundle:nil] autorelease];
        }

    }
    [[self navigationController] pushViewController:viewController animated:YES];                    
}


#pragma mark -
#pragma mark UITableViewDataSource
/////////////////////////////////////////////////////////////////////////////////////////////////
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSLog(@"numberOfRowsInSection: %d, %d",section, [[_dataSourceArray objectAtIndex:section] count]);
    return [[_dataSourceArray objectAtIndex:section] count];
}
/////////////////////////////////////////////////////////////////////////////////////////////////
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    switch (section) {
        case 0:
            return @"기본";
            break;
        case 1:
            return @"목록";
            break;
        case 2:
            return @"관리";
            break;
    }
    return @"";
}
/////////////////////////////////////////////////////////////////////////////////////////////////
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
	if (cell == nil){
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCellIdentifier] autorelease];
		cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.textAlignment = UITextAlignmentCenter;
        cell.textLabel.textColor = [UIColor grayColor];
        cell.textLabel.highlightedTextColor = [UIColor blackColor];
        cell.textLabel.font = [UIFont systemFontOfSize:12.0];
	}
	
	cell.textLabel.text = [[_dataSourceArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

	return cell;
}
@end
